package smartlifev30.com.sdk.api.gateway_app;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import smartlifev30.com.sdk.util.JsonUtil;
import smartlifev30.com.sdk.api.CallBack;
import smartlifev30.com.sdk.api.ConstantGateway;
import smartlifev30.com.sdk.bean.request.GetUnReadMsgNumRequest;
import smartlifev30.com.sdk.bean.request.MessageQueryRequest;
import smartlifev30.com.sdk.bean.request.SetReadMessageIdRequest;
import smartlifev30.com.sdk.net.baiwei.NetManager;

/**
 * Created by tys on 2018/8/15.
 */

public class MessageMgmtImpl implements IMessageMgmt {

    @Override
    public void msgQuery(@NonNull String userName, @NonNull String token, @NonNull String sn,
                         @NonNull String type, @NonNull Integer begin, @NonNull Integer count,
                         @Nullable Integer deviceId, @NonNull CallBack<String> callBack) {
        MessageQueryRequest messageQueryRequest = new MessageQueryRequest();
        messageQueryRequest.setFrom(userName);
        messageQueryRequest.setTo(sn);
        messageQueryRequest.setMsg_id(callBack.getMsgId());
        messageQueryRequest.setMsg_class(ConstantGateway.MSG_CLASS_MESSAGE);
        messageQueryRequest.setMsg_name("msg_query");
        messageQueryRequest.setMsg_type(ConstantGateway.MSG_TYPE_GET);
        messageQueryRequest.setToken(token);
        MessageQueryRequest.Message message = messageQueryRequest.new Message();
        message.setType(type);
        message.setBegin(begin);
        message.setCount(count);
        message.setDevice_id(deviceId);
        messageQueryRequest.setMessage(messageQueryRequest.new Message());
        NetManager.getInstance().sendMessage(JsonUtil.toString(messageQueryRequest));
    }

    @Override
    public void setReadMsgId(@NonNull String userName, @NonNull String token, @NonNull String sn, @NonNull String type,
                             @NonNull Integer msgId, @NonNull CallBack<String> callBack) {
        SetReadMessageIdRequest setReadMessageId = new SetReadMessageIdRequest();
        setReadMessageId.setFrom(userName);
        setReadMessageId.setTo(sn);
        setReadMessageId.setMsg_id(callBack.getMsgId());
        setReadMessageId.setMsg_class(ConstantGateway.MSG_CLASS_MESSAGE);
        setReadMessageId.setMsg_name("read_msgid_set");
        setReadMessageId.setMsg_type(ConstantGateway.MSG_TYPE_SET);
        setReadMessageId.setToken(token);
        SetReadMessageIdRequest.Message message = setReadMessageId.new Message();
        message.setType(type);
        message.setId(msgId);
        NetManager.getInstance().sendMessage(JsonUtil.toString(setReadMessageId));
    }

    @Override
    public void getUnReaMsgNum(@NonNull String userName, @NonNull String token, @NonNull String sn,
                               @NonNull String type, @NonNull CallBack<String> callBack) {
        GetUnReadMsgNumRequest getUnReadMsgNumRequest = new GetUnReadMsgNumRequest();
        getUnReadMsgNumRequest.setFrom(userName);
        getUnReadMsgNumRequest.setTo(sn);
        getUnReadMsgNumRequest.setMsg_id(callBack.getMsgId());
        getUnReadMsgNumRequest.setMsg_class(ConstantGateway.MSG_CLASS_MESSAGE);
        getUnReadMsgNumRequest.setMsg_name("unread_num_get");
        getUnReadMsgNumRequest.setMsg_type(ConstantGateway.MSG_TYPE_GET);
        getUnReadMsgNumRequest.setToken(token);
        getUnReadMsgNumRequest.setMessage(getUnReadMsgNumRequest.new Message(type));
        NetManager.getInstance().sendMessage(JsonUtil.toString(getUnReadMsgNumRequest));
    }





}
